package com.wumeng.interview.view;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;

import com.wumeng.interview.R;
import com.wumeng.interview.databinding.ActivityMediaPlayerBinding;

/**
  * @Time : 2021/8/2
  * @Author : Wu-Meng
  * @Description :
 */
public class MediaPlayerActivity extends AppCompatActivity implements View.OnClickListener {

    private MediaPlayer mMediaPlayer,mMediaPlayer2;

    private ActivityMediaPlayerBinding mediaPlayerBinding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mediaPlayerBinding = DataBindingUtil.setContentView(this,R.layout.activity_media_player);
        initClick();
        initData();
    }

    /**
     * 初始化登录
     */
    private void initClick() {
        mediaPlayerBinding.btnSuccess.setOnClickListener(this);
        mediaPlayerBinding.btnError.setOnClickListener(this);
    }

    /**
     * 初始化数据
     */
    private void initData() {
        mMediaPlayer = MediaPlayer.create(this,R.raw.pass);
        mMediaPlayer2 = MediaPlayer.create(this,R.raw.error);
    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        switch (id) {
            case R.id.btn_success:
                mMediaPlayer.start();
                break;
            case R.id.btn_error:
                mMediaPlayer2.start();
                break;
            default:
                break;
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mMediaPlayer.release();
        mMediaPlayer2.release();
    }
}